package com.htthorizon.model.service;

import java.sql.SQLIntegrityConstraintViolationException;
import java.util.List;
import com.htthorizon.common.core.exception.ServiceException;
import com.htthorizon.model.request.SysUserModelReq;
import com.htthorizon.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.htthorizon.model.mapper.SysUserModelMapper;
import com.htthorizon.model.domain.SysUserModel;

/**
 * 用户对应模型的操作权限Service业务层处理
 *
 * @author mark
 * @date 2023-11-16
 */
@Service
public class SysUserModelServiceImpl implements ISysUserModelService
{
    @Autowired
    private SysUserModelMapper sysUserModelMapper;


    /**
     * 查询用户对应模型的操作权限
     *
     * @param modelId 模型可编辑的用户
     * @return 用户列表
     */
    @Override
    public List<SysUser> selectSysUserModelByModelId(Long modelId)
    {
        return sysUserModelMapper.selectSysUserModelByModelId(modelId);
    }

    /**
     * 查询用户对应模型的操作权限列表
     *
     * @param sysUserModel 用户对应模型的操作权限
     * @return 用户对应模型的操作权限
     */
    @Override
    public List<SysUserModelReq> selectSysUserModelList(SysUserModelReq sysUserModel)
    {
        return sysUserModelMapper.selectSysUserModelList(sysUserModel);
    }

    /**
     * 新增用户对应模型的操作权限
     *
     * @param sysUserModel 用户对应模型的操作权限
     * @return 结果
     */
    @Override
    public int insertSysUserModel(SysUserModel sysUserModel)
    {
        int result = 0;
        try {
            result = sysUserModelMapper.insertSysUserModel(sysUserModel);
        }catch (Exception e){
            throw new ServiceException("请勿重复添加！");
        }
        return result;
    }

    /**
     * 删除用户对应模型的操作权限信息
     *
     * @param userId 用户对应模型的操作权限主键
     * @param modelId 模型的主键
     * @return 结果
     */
    @Override
    public int deleteSysUserModelByUserId(Long userId,Long modelId)
    {
        return sysUserModelMapper.deleteSysUserModelByUserId(userId,modelId);
    }
}
